package com.edwin.websitebe.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.edwin.websitebe.mapper.UserMapper;
import com.edwin.websitebe.model.User;
import com.edwin.websitebe.service.UserService;
import com.edwin.websitebe.util.HttpUtil;
import com.edwin.websitebe.util.TokenUtil;
import org.springframework.boot.web.server.Http2;
import org.springframework.http.HttpHeaders;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
    @Override
    public User getByUsername(String username) {
        LambdaQueryWrapper<User> wrapper = new QueryWrapper<User>().lambda()
                .eq(User::getUsername, username);
        return getOne(wrapper);
    }

    @Override
    public User getLoginUser() {
        String token = HttpUtil.getHeader(HttpHeaders.AUTHORIZATION);
        Long userId = TokenUtil.getUserId(token);
        return this.getById(userId);
    }
}
